package teacher;

import java.io.IOException;
import course.shared.PMF;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.jdo.PersistenceManager;

/**
 * Servlet implementation class addTeacherServlet
 */
public class addTeacherServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String nextJSP = "/ma_course.jsp";

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		
		String name = request.getParameter("teaname");
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try{
			Teacher t = new Teacher(name);
			pm.makePersistent(t);
		} finally {
		    pm.close();
		}
		response.sendRedirect(nextJSP);
		return;
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
